#include<iostream>
using namespace std;

#define e 300
char a[e][e];
char b[e];
char c[e];
int op[2*e];
void sets(int &i,int w)
{
	char ch1;
	ch1=b[++i];
	int r=0;
	while(ch1!='}')
	{
		a[w][r++]=ch1;
		ch1=b[++i];
	}
	
	a[w][r]=0;
	
}


void add(int n,int m)
{
	int al[200]={0};
	int t=0; 
	int n1=0,m1=0;
	char chn=a[n][n1++],chm=a[m][m1];
	while(chn)
	{
		al[chn]++;
		chn=a[n][n1++];
	}
	while(chm)
	{
		al[chm]++;
		chm=a[m][m1++];
		
	}
	int w,w1;
	for(w=0,w1=0; w<27; w++)
	{
		if(al[w+'A'])
		{
			a[n][w1++]=w+'A';
		}
	}
		a[n][w1]=0;
}
void mil(int n,int m)
{
	char al[200]={0};
	int t=0; 
	int n1=0,m1=0;
    char chn=a[n][n1++],chm=a[m][m1++];
	while(chn)
	{
		al[chn]++;
		chn=a[n][n1++];
	}

	while(chm)
	{
		al[chm]--;
		chm=a[m][m1++];
		
	}
	int w,w1;
	for(w=0,w1=0; w<27; w++)
	{
		if(al[w+'A']>0)
		{
			a[n][w1++]=w+'A';
		}
	}
		a[n][w1]=0;
}
void puls(int n,int m)
{
	char al[200]={0};
	int t=0;
	int n1=0,m1=0;
	char chn=a[n][n1++],chm=a[m][m1++];
	while(chn)
	{
		al[chn]++;
		chn=a[n][n1++];
	}
	while(chm)
	{
		al[chm]++;
		chm=a[m][m1++];
	}
	int w,w1;
	for(w=0,w1=0; w<27; w++)
	{
		if(al[w+'A']>1)
		{
			a[n][w1++]=w+'A';
		}
		
	}
	a[n][w1]=0;
}

void trans()
{
	struct listack
	{ 
		char str[e];
		int top;
	}stack;

	
	stack.top=-1;

	char ch;
	int i=0,t=0,w=1;
	ch=b[i];
	while(ch)
	{
		switch (ch)
		{
		case' ':break;
		case'(':   stack.top++; stack.str[stack.top]=ch;
			break;
		case')': while(stack.str[stack.top]!='(' && stack.top>-1)
				 {
					op[t++]=stack.str[stack.top]+256;
					stack.top--;
				 } 
				stack.top--;
				break;
		case'{':op[t++]=w;
				sets(i,w);
				w++;
				break;
		case'+':if(stack.top!=-1 && stack.str[stack.top]!='(' &&stack.top>-1)
				{
					op[t++]=stack.str[stack.top]+256;
					stack.top--;
				}
					stack.top++;
					stack.str[stack.top]=ch;
					break;
		case '-':
			if(stack.top!=-1 && stack.str[stack.top]!='(' && stack.top>-1)
				{
					op[t++]=stack.str[stack.top]+256;
					stack.top--;
				}
					stack.str[++stack.top]=ch;
					break;
		case'*':stack.top++;
				stack.str[stack.top]=ch;
				break;
		}
		i++;
		ch=b[i];
			
	}
	while(stack.top>-1)
	{
		op[t++]=stack.str[stack.top]+256;
		stack.top--;
	}
	op[t]=0;
}
void oper(void)
{
	int d[e];
	int ch;
	int i=0,t=0,y=-1; 
	ch=op[t++];
	while(ch)
	{
		if(ch<256)
		{
			y++;
			d[y]=ch; 
		}
		if('*'==ch-256)
		{
			puls(d[y-1],d[y]);
			y--;
		}
		if('+'==ch-256)
		{
			add(d[y-1],d[y]);
			y--;
		}
		if('-'==ch-256)
		{
			mil(d[y-1],d[y]);
			y--;
		}
		ch=op[t++];
	}

}

int main()
{
	int i,n,m;
	while(cin.getline(b,266))
	{
		trans();
		oper();
		cout<<"{"<<a[1]<<"}"<<endl;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		memset(op,0,sizeof(op));
	}

}
